package com.labot.util;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class FilePropertiesUtils {

	public static Map<String, String> getProperties(File file) {
		Map<String, String> properties = new HashMap<String, String>();
		try {
			FileInputStream fstream = new FileInputStream(file);
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			
			// Read File Line By Line
			while ((strLine = br.readLine()) != null) {
				try {
					String[] property = strLine.split("=");
					properties.put(property[0], property[1]);
				} catch (Exception e) {
					e.printStackTrace();
				}
				// Print the content on the console
				System.out.println(strLine);
			}
			
			// Close the input stream
			in.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
		return properties;
	}
}
